package com.wang.config;

import com.alibaba.druid.pool.DruidDataSource;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

/**
 * @Classname DbConfig
 * @Description TODO
 * @Date 2024/5/22 11:07
 * @Created by pc
 */
@Data
@Configuration
@ConfigurationProperties(prefix = "spring.datasource")
public class DbConfig {
    private String url;
    private String username;
    private String password;

    @Bean
    public DataSource getDataSource(){
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setUrl(url);
        dataSource.setUsername(username);
        dataSource.setPassword(password);
        return dataSource;
    }
}
